package SFT;

/** class representing the difference between two function: "func" on the one hand, and the function defined by
 * input timeElement as the other.*/
public class diffFuncTm extends abstractFunction {
	private Function tmFunc;
	private Function function;
	private int tmPlaceMark;
	
	public diffFuncTm(TimeElements newTm, Function func) {
		this.tmFunc=newTm.convertToFunc();
		this.tmPlaceMark=(int) newTm.getFrom();
		this.function=func;
	}

	@Override
	public Complex apply(int i) {
		/*tmPlaceMark is added so that the phase of the function is kept. That is to say
		 * that originally, we simply moved the tm function as it was learned to the 
		 * beginning of the segment. but then, the phase of the resulting function was changed.
		 * A better solution was to keep the "0" of the tmFunc at the "0" of the periodic segment.*/
		return Complex.Sub(function.apply(i), tmFunc.apply(i-tmPlaceMark));
	}

	@Override
	public int maxVal() {
		return function.maxVal();
	}

}
